/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Model.Dao;

import Model.Pojo.Loainhanvien;
import Model.Pojo.Parameters;
import Model.Util.HibernateUtil;
import java.util.List;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;

/**
 *
 * @author THANH QUAN
 */
public class DAOLoaiNhanVien {
    public List<Loainhanvien> DanhSachLoaiNhanVien() throws Exception
    {
        List<Loainhanvien> dsLoaiNV = null;
        Session session = HibernateUtil.getSessionFactory().openSession();
        try
        {
            String hql = "from Loainhanvien";
            dsLoaiNV = DAOProvider.Select(session, hql, new Parameters[]{});
        }
        catch(HibernateException ex)
        {
            System.out.println(ex.getMessages());
        }
        finally{
            session.close();
        }
        return dsLoaiNV;
    }
    
    public void Insert(Loainhanvien loainv)
    {
        Session session = HibernateUtil.getSessionFactory().openSession();
        Transaction tran = null;
        try
        {
            tran = session.beginTransaction();
            session.save(loainv);
            tran.commit();
        }
        catch(HibernateException ex)
        {
            System.out.println(ex.getMessages());
        }
        finally{
            session.close();
        }
    }
    
    public Loainhanvien ThongTinLoaiNhanVien(int id)
    {
        Loainhanvien result = null;
        Session session = HibernateUtil.getSessionFactory().openSession();
        try
        {
            String hql = "from Loainhanvien lnv where lnv.Id = "+id;
            Query query = session.createQuery(hql);
            result = (Loainhanvien)query.list().get(0);
        }
        catch(HibernateException ex)
        {
            System.out.println(ex.getMessages());
        }
        finally{
            session.close();
        }
        return result;
    }
}
